﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MyProfile : System.Web.UI.Page
{
    /// <summary>
    /// 页面载入前
    /// </summary>
    public void Page_PreInit()
    {
        if (Session["myTheme"] != null)//判断会话中主题是否为空
        {
            this.Theme = Session["myTheme"].ToString();//设置页面主题
        }
    }

    /// <summary>
    /// 页面载入
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserID"] == null)//判断会话中用户信息是否为空
        {
            //弹出错误信息，并转到登陆页面
            this.Response.Write("<script>alert('" + "请先登陆" + "');</script>");
            this.Response.Output.WriteLine("<script language=\"javascript\">");
            this.Response.Output.WriteLine("parent.window.location=\"" + this.Request.ApplicationPath + "/Default.aspx\"");
            this.Response.Output.WriteLine("</script>");
        }
        else//若用户以登陆
        {
            Label1.Text=Session["UserID"].ToString();//显示用户ID
            Label2.Text = Session["UserName"].ToString();//显示用户名
            DataTable dt = BLL.CallProc.GetBorrowInfoByUserID(Session["UserID"].ToString()).Tables[0];//查询用户的借书历史

            //从查询结果中取出信息并生成列
            ButtonField s = new ButtonField();
            s.ButtonType = ButtonType.Link;
            s.DataTextField = dt.Columns["BookID"].ToString();
            s.CommandName = "Select";
            s.HeaderText = "图书编号";
            GridView1.Columns.Add(s);

            BoundField bFild;
            //从查询结果中取出信息并生成列
            bFild = new BoundField();
            bFild.DataField = dt.Columns["BookName"].ToString();
            bFild.HeaderText = "书名";
            GridView1.Columns.Add(bFild);

            //从查询结果中取出信息并生成列
            bFild = new BoundField();
            bFild.DataField = dt.Columns["BorrowDate"].ToString();
            bFild.HeaderText = "借书日期";
            GridView1.Columns.Add(bFild);

            //从查询结果中取出信息并生成列
            CheckBoxField chk = new CheckBoxField();
            chk.HeaderText = "是否归还";
            chk.DataField = dt.Columns["IsReturned"].ToString();
            GridView1.Columns.Add(chk);

            //从查询结果中取出信息并生成列
            bFild = new BoundField();
            bFild.DataField = dt.Columns["Author"].ToString();
            bFild.HeaderText = "作者";
            GridView1.Columns.Add(bFild);

            //从查询结果中取出信息并生成列
            bFild = new BoundField();
            bFild.DataField = dt.Columns["PageCount"].ToString();
            bFild.HeaderText = "页数";
            GridView1.Columns.Add(bFild);

            //从查询结果中取出信息并生成列
            bFild = new BoundField();
            bFild.DataField = dt.Columns["WordCount"].ToString();
            bFild.HeaderText = "字数";
            GridView1.Columns.Add(bFild);

            GridView1.DataSource = dt;//设置列表控件数据源
            GridView1.DataBind();//绑定列表控件
            string[] key ={ "BookID" };//设置主键
            GridView1.DataKeyNames = key;//设置主键
        }
    }
}
